<?php
/**
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package Textbook
* @subpackage User
* @author Aljaz Srebrnic <a2piratesoft@gmail.com>;
* @author E. Pavletič
* @copyright 2009 a2PirateSoftware
* @license GPL License v3 <http://www.gnu.org/copyleft/gpl.html>
*/

class Textbook_Form_ContactForm extends ZNF_Action_ActionForm {
  // Identifikator ponudnika učbenika
  private $userId = null;
  // Sporočilo uporabnika ponudniku
  private $message = null;
  // Kontaktne informacije uporabnika (iskalca)
  private $email = null;
  private $phone = null;
  private $cell = null;
  private $skype = null;
  private $icq = null;
  private $msn = null;
    
  private $emailPattern = "^[!-'*+=?{-~/-9A-Z^-z-]+(\.[!-'*+=?{-~/-9A-Z^-z-]+)*@[!-'*+=?{-~/-9A-Z^-z-]+\.[!-'*+=?{-~/-9A-Z^-z-]{2,}";

  public function populate() {
    if (isset($_POST['userId']) && (strlen(trim($_POST['userId'])) > 0))
      $this->userId = intval($_POST['userId']);
    if (isset($_POST['message']) && (strlen(trim($_POST['message'])) > 0))
      $this->message = htmlspecialchars(addslashes($_POST['message']));
    if (isset($_POST['email']) && (strlen(trim($_POST['email'])) > 0))
      $this->email = htmlspecialchars(addslashes($_POST['email']));
    if (isset($_POST['phone']) && (strlen(trim($_POST['phone'])) > 0))
      $this->phone = htmlspecialchars(addslashes($_POST['phone']));
    if (isset($_POST['cell']) && (strlen(trim($_POST['cell'])) > 0))
      $this->cell = htmlspecialchars(addslashes($_POST['cell']));
    if (isset($_POST['skype']) && (strlen(trim($_POST['skype'])) > 0))
      $this->skype = htmlspecialchars(addslashes($_POST['skype']));
    if (isset($_POST['icq']) && (strlen(trim($_POST['icq'])) > 0))
      $this->icq = htmlspecialchars(addslashes($_POST['icq']));
    if (isset($_POST['msn']) && (strlen(trim($_POST['msn'])) > 0))
      $this->msn = htmlspecialchars(addslashes($_POST['msn']));
  }


  public function validate() {
    $errors = new ZNF_Action_ActionErrors();
    $translation =  new ZNF_Presentation_Translation('Textbook', $_SESSION['znf']['lang']);
        
    if ($this->getUserId() == null)
      $errors->addError(1, $translation->get('errorSellerNotValid'));
    if ($this->getMessage() == null)
      $errors->addError(2, $translation->get('errorMessageNotValid'));
    if(($this->getEmail() == null) || ereg($this->emailPattern, $this->getEmail()) === FALSE)
      $errors->addError(2, $translation->get('errorEmailNotValid'));
        
    return $errors;
  }


  public function getUserId() {
    return $this->userId;
  }

  public function getMessage() {
    return $this->message;
  }

  public function getEmail() {
    return $this->email;
  }

  public function getPhone() {
    return $this->phone;
  }

  public function getCell() {
    return $this->cell;
  }

  public function getSkype() {
    return $this->skype;
  }

  public function getIcq() {
    return $this->icq;
  }

  public function getMsn() {
    return $this->msn;
  }
}

